package graphics.system;
import java.io.Serializable;

import org.lwjgl.opengl.GL11;
public class Color implements Serializable {
	public static final Color black = new Color(0, 0, 0, 1);
	public static final Color white = new Color(1, 1, 1, 1);
	public static final Color red = new Color(1, 0, 0, 1);
	public static final Color green = new Color(0, 1, 0, 1);
	public static final Color blue = new Color(0, 0, 1, 1);
	public static final Color yellow = new Color(1, 1, 0, 1);
	public float r, g, b, a;
	public Color() {
		this(0, 0, 0, 1);
	}
	public Color(float r, float g, float b, float a) {
		this.r = r;
		this.g = g;
		this.b = b;
		this.a = a;
	}
	public void set() {
		GL11.glColor4f(r, g, b, a);
	}
	public Color mul(float f) {
		return new Color(r * f, g * f, b * f, a);
	}
	public Color mulA(float f) {
		return new Color(r * f, g * f, b * f, a * f);
	}
	public Color withAlpha(float newalpha) {
		return new Color(r, g, b, newalpha);
	}
	public static Color blend(Color c0, Color c1, float b) {
		Color res = new Color();
		res.r = c0.r * (1 - b) + c1.r * b;
		res.g = c0.g * (1 - b) + c1.g * b;
		res.b = c0.b * (1 - b) + c1.b * b;
		res.a = c0.a * (1 - b) + c1.a * b;
		return res;
	}
	public String toFileString() {
		return "[" + r + "," + g + "," + b + "," + a + "]";
	}
	public static Color fromFileString(String s) {
		Color c = new Color();
		s = s.substring(1, s.length() - 1);
		String l[] = s.split(",");
		c.r = Float.valueOf(l[0]);
		c.g = Float.valueOf(l[1]);
		c.b = Float.valueOf(l[2]);
		c.a = Float.valueOf(l[3]);
		return c;
	}
}
